package cn.iocoder.yudao.module.search.api.search;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.search.api.search.dto.*;
import cn.iocoder.yudao.module.search.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * RPC 服务 - 搜索管理
 *
 * @author 芋道源码
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 搜索管理")
public interface SearchApi {

    String PREFIX = ApiConstants.PREFIX + "/search";

    // ========== 索引管理 ==========

    @PostMapping(PREFIX + "/index/create")
    @Operation(summary = "创建索引")
    CommonResult<Boolean> createIndex(@Valid @RequestBody SearchIndexReqDTO reqDTO);

    @DeleteMapping(PREFIX + "/index/delete")
    @Operation(summary = "删除索引")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    @Parameter(name = "indexName", description = "索引名称", example = "user_index", required = true)
    CommonResult<Boolean> deleteIndex(@RequestParam("tenantId") Long tenantId,
                                     @RequestParam("indexName") String indexName);

    @GetMapping(PREFIX + "/index/exists")
    @Operation(summary = "检查索引是否存在")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    @Parameter(name = "indexName", description = "索引名称", example = "user_index", required = true)
    CommonResult<Boolean> existsIndex(@RequestParam("tenantId") Long tenantId,
                                     @RequestParam("indexName") String indexName);

    @GetMapping(PREFIX + "/index/get")
    @Operation(summary = "获取索引信息")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    @Parameter(name = "indexName", description = "索引名称", example = "user_index", required = true)
    CommonResult<SearchIndexRespDTO> getIndex(@RequestParam("tenantId") Long tenantId,
                                             @RequestParam("indexName") String indexName);

    @GetMapping(PREFIX + "/index/list")
    @Operation(summary = "获取租户所有索引列表")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    CommonResult<List<SearchIndexRespDTO>> listIndexes(@RequestParam("tenantId") Long tenantId);

    // ========== 文档管理 ==========

    @PostMapping(PREFIX + "/document/create")
    @Operation(summary = "创建文档")
    CommonResult<String> createDocument(@Valid @RequestBody SearchDocumentReqDTO reqDTO);

    @PutMapping(PREFIX + "/document/update")
    @Operation(summary = "更新文档")
    CommonResult<Boolean> updateDocument(@Valid @RequestBody SearchDocumentReqDTO reqDTO);

    @DeleteMapping(PREFIX + "/document/delete")
    @Operation(summary = "删除文档")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    @Parameter(name = "indexName", description = "索引名称", example = "user_index", required = true)
    @Parameter(name = "documentId", description = "文档ID", example = "1", required = true)
    CommonResult<Boolean> deleteDocument(@RequestParam("tenantId") Long tenantId,
                                       @RequestParam("indexName") String indexName,
                                       @RequestParam("documentId") String documentId);

    @GetMapping(PREFIX + "/document/get")
    @Operation(summary = "获取文档")
    @Parameter(name = "tenantId", description = "租户ID", example = "1", required = true)
    @Parameter(name = "indexName", description = "索引名称", example = "user_index", required = true)
    @Parameter(name = "documentId", description = "文档ID", example = "1", required = true)
    CommonResult<SearchDocumentRespDTO> getDocument(@RequestParam("tenantId") Long tenantId,
                                                   @RequestParam("indexName") String indexName,
                                                   @RequestParam("documentId") String documentId);

    @PostMapping(PREFIX + "/document/bulk")
    @Operation(summary = "批量操作文档")
    CommonResult<SearchBulkRespDTO> bulkDocument(@Valid @RequestBody SearchBulkReqDTO reqDTO);

    // ========== 搜索查询 ==========

    @PostMapping(PREFIX + "/query")
    @Operation(summary = "搜索查询")
    CommonResult<SearchQueryRespDTO> search(@Valid @RequestBody SearchQueryReqDTO reqDTO);

}
